Friday, April 28, 2006

Programmers do the dumbest things

Ever do something really stupid in your code? I bet you can't say "No" with a straight face. But, don't you get irritated when you encounter someone else's blunders. I have found some real dillys lately and thought I might run them by anyone that ever reads my blog, which at this point is not a lot of people.

It seems that a lot of self-named .NET developers totally don't understand Exception Handling! For example, explain the need for the following Try Catch block, if you can.

private void DoNothing()
{
   try
   {
      // do some code
   }
   catch(Exception ex)
   {
      throw(ex);
   }
}

Did it never occur to the writer of this code that if they had not coded the try catch, that the results of a failure in the DoNothing method will be exactly the same. The try catch as coded basically is an unhandled exception, which could have been raised without the try catch.

Here's one more that completely baffled me when I came upon it recently.

Try
   IO.File.Move(oldPath, newPath)
Catch (ex As Exception)
   IO.File.Move(oldPath, newPath)
End Try

Go Figure! What is this? "If at first you don't succeed, Try, Try again?"

Take a minute and comment with something really dumb that you have done or seen.

4 Comments:

At 8:55 AM, Blogger Naren Ranganathan said...

Is there an easy method in Visual C# 2005 to write a form load event. I am coming from VB6 and VB2005 where in you can pick on the item and browse the event on the right side.

 
At 2:29 PM, Blogger Les Smith said...

There are a couple of ways of doing it.

First, double-click on the form, just like VB/VB.Net. The form load event will be opened or created.

Secondly, Select the form in project explorer, click the Events button in the properties window, scroll to the Load event and double-click it.

 
At 11:34 PM, Blogger Unknown said...

i just want that i want a knowledge about dot net freamework,
and some question on that perticualr topic?

 
At 8:31 AM, Blogger Konasports.com said...

Finding Start and End Dates of Previous Week.

I found your article after reading another one that the DayOfWeek is an enumeration (1-7) so I tested out a slightly different way to do it.

dtSaleStart.Value = System.DateTime.Today.AddDays((System.DateTime.Today.DayOfWeek - 1) * -1)
dtSaleEnd.Value = System.DateTime.Today.AddDays((System.DateTime.Today.DayOfWeek - 7) * -1)

sets the 2 dates to the monday and sunday of this week. Just thought it was a neat alternative to the select case statment in your code. Your article helped me out a lot, Thanks.

 

Post a Comment

<< Home